//
//  CustomSalTableCell.m
//  YouGoWeGo
//
//  Created by LiuFei on 14/11/20.
//  Copyright (c) 2014年 LiuFei. All rights reserved.
//

#import "CustomSalTableCell.h"
#import "SaleModel.h"
#import "UIImageView+WebCache.h"
@implementation CustomSalTableCell

- (void)dealloc
{
    [_nameLabel release];
    [_image release];
    [_priceLabel release];
    [_startAreaLabel release];
  
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2.png"]];
        [_image setFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height / 2)];
        [self addSubview:_image];
        [_image release];
        
        self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, self.image.frame.size.height / 2, self.image.frame.size.width / 3, self.image.frame.size.height / 3 * 2)];
        [_nameLabel setFont:[UIFont systemFontOfSize:20]];
        [_nameLabel setTextColor:[UIColor blueColor]];
        [self.image addSubview:_nameLabel];
        [_nameLabel release];
        
        self.startAreaLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.image.frame.size.width / 2 + 50, self.image.frame.size.height / 2 + 30, self.image.frame.size.width / 3, self.image.frame.size.height / 3 * 2)];
        [_startAreaLabel setTextColor:[UIColor blueColor]];
        [self.image addSubview:_startAreaLabel];
        [_startAreaLabel release];
        
        self.priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, self.image.frame.size.height / 2 + 30, self.image.frame.size.width / 2, self.image.frame.size.height / 3 * 2)];
        [_priceLabel setTextColor:[UIColor blueColor]];
        [self.image addSubview:_priceLabel];
        [_priceLabel release];
        //监听
        [self addObserver:self forKeyPath:@"model" options:NSKeyValueObservingOptionNew context:nil];
    }
    return self;
}
//监听方法
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{

    if ([keyPath isEqualToString:@"model"]) {
        [self.image setImageWithURL:[NSURL URLWithString:self.model.cover]];
        self.nameLabel.text = self.model.title;
        self.startAreaLabel.text = self.model.depart_place;
        self.priceLabel.text = [NSString stringWithFormat:@"%@", self.model.market_price];
        
    }

}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
